package com.design.designmode.action.mediator;

/**
 * @author hxl
 * @since 2023-04-18
 */
public class ConcreteMediator extends Mediator {
    private ColleagueA colleagueA;
    private ColleagueB colleagueB;
    private ColleagueC colleagueC;


    public void setColleagueA(ColleagueA colleagueA) {
        this.colleagueA = colleagueA;
    }

    public void setColleagueB(ColleagueB colleagueB) {
        this.colleagueB = colleagueB;
    }

    public void setColleagueC(ColleagueC colleagueC) {
        this.colleagueC = colleagueC;
    }


    @Override
    public void sendMessage(String message, Colleague colleague) {
        if (colleague == colleagueA) {
            // A 同事发给B 和 C
            colleagueB.receive(message);
            colleagueC.receive(message);
        }

        if (colleague == colleagueB) {
            colleagueC.receive(message);
        }

        if (colleague == colleagueC) {
            colleagueA.receive(message);
        }
    }
}
